package cc.htdf.gwc.forecast.controller;

import cc.htdf.gwc.forecast.domain.response.ResponseBody;
import cc.htdf.gwc.forecast.domain.response.ResponseCode;
import cc.htdf.gwc.forecast.service.StationDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by JT on 2017/10/9.
 */
@RestController
@RequestMapping("/data")
public class StationDataController {

    @Autowired
    private StationDataService stationDataService;

    /**
     * 查询成都国家站预报数据接口
     * @param stations：站点
     * @param elements：要素
     * @param modelRunDateTime：发布时间
     */
    @GetMapping("/ChengDu")
    @CrossOrigin
    public ResponseBody filterData(@RequestParam("stations") String stations,
                           @RequestParam("elements") String elements,
                           @RequestParam("modelRunDateTime" ) String modelRunDateTime,
                           @RequestParam("validTimes") String validTimes) {

        List<Map<String, Object>> list = stationDataService.findChengDuStatioinForecastDataByStationsAndModelAndValidTime(stations, elements, modelRunDateTime, validTimes);
        ResponseBody body = new ResponseBody(ResponseCode.STATUS_SUCCESS, "数据获取成功！", list);
        return body;
    }

    /**
     * 根据台站、要素、预报时间查询数据
     *
     * @param stations
     * @param elements
     * @param validDate
     * @return
     */
    @GetMapping("/ChengDu/validDate")
    @CrossOrigin
    public ResponseBody fetchForcastDataByValidDate(@RequestParam("stations") String stations,
                                            @RequestParam("elements") String elements,
                                            @RequestParam("validDate") String validDate) {
        List<Map<String, Object>> list = stationDataService.findChengDuStationForecastDataByStationsAndValidDate(stations, elements, validDate);
        ResponseBody body = new ResponseBody(ResponseCode.STATUS_SUCCESS, "数据获取成功！", list);
        return body;
    }

    /**
     * 根据台站、要素、发布时间、预报时间
     * @param stations
     * @param elements
     * @param modelRunDateTime
     * @param validTimes
     * @return
     */
    @GetMapping("/ChengDu/score")
    @CrossOrigin
    public ResponseBody filterDataScore(@RequestParam("stations") String stations,
                                   @RequestParam("elements") String elements,
                                   @RequestParam("modelRunDateTime" ) String modelRunDateTime,
                                   @RequestParam("validTimes") String validTimes) {

        List<Map<String, Object>> list = stationDataService.findChengDuData(stations, elements, modelRunDateTime, validTimes);
        ResponseBody body = new ResponseBody(ResponseCode.STATUS_SUCCESS, "数据获取成功！", list);
        return body;
    }

    /**
     *
     * @param stations
     * @param elements
     * @param modelRunDateTime: yyyyMMdd
     * @param startValidTime:yyyyMMddHH
     * @param endValidTime:yyyyMMddHH
     * @return
     */
    @GetMapping("/ChengDu/validTimeRange")
    @CrossOrigin
    public ResponseBody fetchDataByModelRunDateTimeAndValidTimes(@RequestParam("stations") String stations,
                                                                 @RequestParam("elements") String elements,
                                                                 @RequestParam("modelRunDateTime" ) String modelRunDateTime,
                                                                 @RequestParam("startValidTime") String startValidTime,
                                                                 @RequestParam("endValidTime") String endValidTime) {
        List<Map<String, Object>> list = stationDataService.findChengDuData(stations, elements, modelRunDateTime, startValidTime, endValidTime);
        ResponseBody body = new ResponseBody(ResponseCode.STATUS_SUCCESS, "数据获取成功！", list);
        return body;
    }


    /**
     * 根据台站号、要素、发布小时，预报时次数查询数据
     * @param station：站号
     * @param elemtns：要素
     * @param hour：发布小时 HH
     * @param times：预报的时次，例如：前12小时：12， 前24小时：24
     * @return
     */
    @GetMapping("/ChengDu/{station}")
    @CrossOrigin
    public ResponseBody fetchDataByStationAndModelHourAndValidTimes(@PathVariable("station") String station,
                                                    @RequestParam("elements") String elemtns,
                                                    @RequestParam("modelhour") String hour,
                                                    @RequestParam("times") String times ) {


        List<Map<String, Object>> list = stationDataService.findChengDuDataByStationAndModelHourAndTimes(station, elemtns, hour, times);
        ResponseBody body = new ResponseBody(ResponseCode.STATUS_SUCCESS, "数据获取成功！", list);
        return body;
    }
}
